package com.ruoyi.web.controller.system;

import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletResponse;

import com.sun.jna.platform.unix.X11;
import org.apache.ibatis.annotations.Param;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.cdRecord;
import com.ruoyi.system.service.IcdRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 充电分析Controller
 * 
 * @author ruoyi
 * @date 2025-07-08
 */
@RestController
@RequestMapping("/system/cdrecord")
public class cdRecordController extends BaseController
{
    @Autowired
    private IcdRecordService cdRecordService;

    /**
     * 查询充电分析列表
     */
//    @PreAuthorize("@ss.hasPermi('system:cdrecord:list')")
//    @GetMapping("/list")
//    public TableDataInfo list(Date time)
//    {
//        startPage();
//        List<Map<String, Object>> list = cdRecordService.selectcdRecordList(time);
//        return getDataTable(list);
//    }

    /**
     * 导出充电分析列表
     */
    @PreAuthorize("@ss.hasPermi('system:cdrecord:export')")
    @Log(title = "充电分析", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public List<Map<String, Object>> export(@Param("scharging_date") String scharging_date,@Param("csName") String csName)
    {
        List<Map<String, Object>> list = cdRecordService.selectcdRecordList(scharging_date,csName);
//        ExcelUtil<cdRecord> util = new ExcelUtil<cdRecord>(list);
//        util.exportExcel(response, list, "充电分析数据");
        return list;
    }

    /**
     * 获取充电分析详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:cdrecord:query')")
    @GetMapping(value = "/{recordId}")
    public AjaxResult getInfo(@PathVariable("recordId") Integer recordId)
    {
        return success(cdRecordService.selectcdRecordByRecordId(recordId));
    }

    /**
     * 新增充电分析
     */
    @PreAuthorize("@ss.hasPermi('system:cdrecord:add')")
    @Log(title = "充电分析", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody cdRecord cdRecord)
    {
        return toAjax(cdRecordService.insertcdRecord(cdRecord));
    }

    /**
     * 修改充电分析
     */
    @PreAuthorize("@ss.hasPermi('system:cdrecord:edit')")
    @Log(title = "充电分析", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody cdRecord cdRecord)
    {
        return toAjax(cdRecordService.updatecdRecord(cdRecord));
    }

    /**
     * 删除充电分析
     */
    @PreAuthorize("@ss.hasPermi('system:cdrecord:remove')")
    @Log(title = "充电分析", businessType = BusinessType.DELETE)
	@DeleteMapping("/{recordIds}")
    public AjaxResult remove(@PathVariable Integer[] recordIds)
    {
        return toAjax(cdRecordService.deletecdRecordByRecordIds(recordIds));
    }
}
